"use strict"
const nunjucks = require('nunjucks');

function render(path, ctx) {
    var
        autoescape = ctx.autoescape === undefined ? true : ctx.autoescape,
        noCache = ctx.noCache || false,
        watch = ctx.watch || false,
        throwOnUndefined = ctx.throwOnUndefined || false,
        red = new nunjucks.Environment(
            new nunjucks.FileSystemLoader('views', {
                noCache: noCache,
                watch: watch,
            }), {
                autoescape: autoescape,
                throwOnUndefined: throwOnUndefined
            });
    if (ctx.filters) {
        for (var f in ctx.filters) {
            red.addFilter(f, opts.filters[f]);
        }
    }
    return env;
}

var red = render('views', {
    watch: true,
    filters: {
        hex: function (n) {
            return '0x' + n.toString(16);
        }
    }
});